package com.smarttiger.zero.admin.controller;

import com.smarttiger.zero.admin.entity.UsersModel;
import com.smarttiger.zero.admin.service.UsersService;
import com.smarttiger.zero.admin.util.SpringContextUtils;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestHeader;

public class BaseController {
    @ModelAttribute
    public void get(@RequestHeader(value = "token", required = false) String token, Model model) {
        if (token != null){
            UsersService bean = SpringContextUtils.getBean(UsersService.class);
            UsersModel user = bean.findByToken(token);
            model.addAttribute("user", user);
        }
    }
}
